//
//  WeiboTabViewController.m
//  WeiboAD
//
//  Created by liu guoqiang on 16/7/22.
//  Copyright © 2016年 com.liu.weiboAD. All rights reserved.
//

#import "WeiboTabViewController.h"
#import "WeiboListViewController.h"
#import "WriteWeiboViewController.h"
#import "PersonInformationViewController.h"


@interface WeiboTabViewController ()<UITabBarControllerDelegate>

@end

@implementation WeiboTabViewController

- (instancetype)initWithUser:(NSDictionary *)user
{
    self = [super init];
    if (self) {
        _user = [NSDictionary dictionary];
        _user = user;
        [self initViewController];
         self.selectedIndex = 1;
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

-(void)initViewController{
    self.tabBar.translucent = NO;
    self.tabBar.barTintColor = [UIColor bgColor];
    [self.tabBar setBackgroundImage:[UIImage imageNamed: @"tabbar_bg"]];
    [self.tabBar setShadowImage:[UIImage new]];
    
    //发送微博
    UINavigationController *writeNaVC = [[UINavigationController alloc]initWithRootViewController:[[WriteWeiboViewController alloc]init]];
    //展示微博
    UINavigationController *weiboNaVC = [[UINavigationController alloc]initWithRootViewController:[[WeiboListViewController alloc]init]];
    //个人信息
    UINavigationController *personNaVC = [[UINavigationController alloc]initWithRootViewController:[[PersonInformationViewController alloc]initWithUser:_user]];
    

    [self addOneChildVC:writeNaVC title:@"发微博" imageName:@"资讯" selectedImageName:@"资讯选中"];
        [self addOneChildVC:weiboNaVC title:@"微博" imageName:@"首页" selectedImageName:@"首页选中"];
    [self addOneChildVC:personNaVC title:@"我的" imageName:@"维护" selectedImageName:@"维护选中"];
    
}

- (void)addOneChildVC:(UIViewController *)viewController title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName{
    //设置标题
    viewController.tabBarItem.title = title;
    UIImage *image = [UIImage imageNamed:imageName];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置图片
    viewController.tabBarItem.image = image;
    //设置高亮图片
    UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
    //ios7有变化
    selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.tabBarItem.selectedImage = selectedImage;
    // UIImage *backgroundImage = [UIImage imageNamed:@"deleteBtn"];
    //UIImageView *imageView = [[UIImageView alloc]initWithImage:backgroundImage];
    
    //self.tabBar.selectionIndicatorImage =  backgroundImage;
    //    [[imageView layer]setShadowOffset:CGSizeMake(15,15)];
    //    [[imageView layer]setShadowRadius:7];
    //    [[imageView layer]setShadowOpacity:1];
    //    [[imageView layer]setShadowColor:[UIColor lightGrayColor].CGColor];
    //    CALayer *lay = imageView.layer;
    //    [lay setMasksToBounds:YES];
    //    [lay setCornerRadius:5.0];
    self.tabBar.tintColor = [UIColor tabTintColor];
    [self addChildViewController:viewController];
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    //    CATransition *animation = [CATransition animation];
    //    [animation setDuration:0.3f];
    //    [animation setType:kCATransitionFade];
    //    [animation setSubtype:kCATransitionFromRight];
    //    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    //    [[self.view layer]addAnimation:animation forKey:@"switchView"];
    //   [UIView animateWithDuration:0.5 animations:^{
    //       self.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"deleteBtn"];
    //       
    //   }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
